.TH std::filesystem::path::replace_filename 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::filesystem::path::replace_filename \- std::filesystem::path::replace_filename

.SH Synopsis
   path& replace_filename( const path& replacement );  \fI(since C++17)\fP

   Replaces a single filename component with replacement.

   Equivalent to: remove_filename(); return operator/=(replacement);.

.SH Parameters

   replacement - path used for replacing the filename component

.SH Return value

   *this

.SH Exceptions

   May throw implementation-defined exceptions.

.SH Example


// Run this code

 #include <filesystem>
 #include <iostream>
 namespace fs = std::filesystem;

 int main()
 {
     std::cout << fs::path("/foo").replace_filename("bar") << '\\n'
               << fs::path("/").replace_filename("bar") << '\\n'
               << fs::path("").replace_filename("pub") << '\\n';
 }

.SH Output:

 "/bar"
 "/bar"
 "pub"

.SH See also

   replace_extension replaces the extension
                     \fI(public member function)\fP
   filename          returns the filename path component
                     \fI(public member function)\fP
   remove_filename   removes filename path component
                     \fI(public member function)\fP
   has_filename      checks if the corresponding path element is not empty
                     \fI(public member function)\fP
